package github.fafaovo.common.guiblock.Screen;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import github.fafaovo.common.guiblock.containers.ExampleBurnMachineContainers;
import github.fafaovo.example;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;


//客户端 各种显示
public class ExampleBurnMachineScreen extends ContainerScreen<ExampleBurnMachineContainers> {

    private final ResourceLocation RESOURCE = new ResourceLocation(example.MOD_ID, "textures/gui/container_2.png");
    private final int textureWidth = 176;
    private final int textureHeight = 166;

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        renderBackground(matrixStack);
        super.render(matrixStack, mouseX, mouseY, partialTicks);
        renderHoveredTooltip(matrixStack, mouseX, mouseY);
    }

    public ExampleBurnMachineScreen(ExampleBurnMachineContainers screenContainer, PlayerInventory inv, ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);
        //首先我们先来讲xSize和ySize，这两个变量时ContainerScreen创建的，用来设定GUI窗口的大小，这里我们就将其设置的和我背景图大小一样。
        this.xSize = textureWidth;
        this.ySize = textureHeight;
        this.guiLeft = 0;
        this.guiTop = 0;
    }

    //其中drawGuiContainerBackgroundLayer的起始点是(0,0)，而drawGuiContainerForegroundLayer的起始点是`
    //( (this.width - this.xSize)/2 , (this.height - this.ySize)/2 )。
    //你应该在drawGuiContainerBackgroundLayer渲染你的背景图，
    // 而在drawGuiContainerForegroundLayer渲染你的组件（字符串，按钮等）。

    @Override
    protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) {
        RenderSystem.color4f(1.0f,1.0f,1.0f,1.0f);

        //物品栏的名字
        this.font.drawText(matrixStack,
                this.playerInventory.getDisplayName(),
                (float)this.playerInventoryTitleX,
                (float) this.playerInventoryTitleY,
                4210752);
        //电量
        this.font.drawText(matrixStack,
                new TranslationTextComponent(
                        Integer.toString(this.getContainer().getIntArray().get(3))),
                50, (float)this.playerInventoryTitleY, 4210752);

        //机器名
        TranslationTextComponent tt = new TranslationTextComponent(example.MOD_ID + ".burn");
        this.font.drawText(matrixStack,
                tt,
                xSize / 2 - font.getStringWidth(tt.getString()) / 2,6, 4210752);

    }



    @Override
    protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int $x, int $y) {
//        this.renderBackground(matrixStack);
//        this.minecraft.getTextureManager().bindTexture(RESOURCE);
//        int i = (this.width - this.xSize) / 2;
//        int j = (this.height - this.ySize) / 2;
//        blit(matrixStack, i, j, 0, 0, xSize, ySize, textureWidth, textureHeight);
        RenderSystem.color4f(1.0f,1.0f,1.0f,1.0f);
        this.minecraft.textureManager.bindTexture(RESOURCE); //图片的宽高要一样

        int x = (this.width - this.xSize) /2;
        int y = (this.height - this.ySize) /2;

        //矩形 位置x y 偏移量x,y 图片大小x,y
        this.blit(matrixStack,x,y,0,0,this.xSize,this.ySize);


        //绘制燃烧的进度条
        int barw = 14;
        int barh = this.getContainer().getIntArray().get(2);
        this.blit(matrixStack,x+102,y+34 + 14 - barh,0,166 + 14 - barh,barw,barh);

        //位置150 9    位置 176 103 大小  17 64 能量条
        int barw1 = 17;
        int barh1 = this.getContainer().getIntArray().get(1);
        this.blit(matrixStack,x+151,y+9 + 64 - barh1,176,103 + 64 - barh1 ,barw1,barh1);
    }

}
